/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.opensudoku.root.solver;

import org.opensudoku.root.SudokuConstants;
import org.opensudoku.root.exceptions.ConcreteNotNeededException;
import org.opensudoku.root.exceptions.InvalidBoxEntryException;
import org.opensudoku.root.exceptions.InvalidDimensionException;
import org.opensudoku.root.exceptions.NoMorePossibilitiesException;
import org.opensudoku.root.exceptions.SudokuException;
import org.opensudoku.root.exceptions.UnIntializedParameterException;
import org.opensudoku.root.fon.Fon;
import org.opensudoku.root.fon.FonResults;
import org.opensudoku.root.vsb.VirtualSudokuBoard;

/**
 *
 * @author sony
 */
public class V2S_Sudoku {
    private V2S_Results V2S_r;
    private int V2S_ExceptionCode;
    private SudokuException V2S_theReason;
    public V2S_Sudoku()
    {
        this.V2S_r=null;
        this.V2S_ExceptionCode=SudokuConstants.EveryThingIsOk;
        this.V2S_theReason=null;
    }
    public void V2S_SolveSafely(VirtualSudokuBoard vsb)
    {
    	if (vsb == null){
    		throw new IllegalArgumentException("Null Sudoku board.");
    	}
        try
        {
            this.V2S_r = V2S_Solver.V2S_ReturnResults(vsb);
        }
        catch (UnIntializedParameterException ex)
        {
           this.V2S_theReason=ex;
           this.V2S_ExceptionCode=SudokuConstants.UnIntializedParameterException;
        }
        catch (ConcreteNotNeededException ex)
        {
           this.V2S_theReason=ex;
           this.V2S_ExceptionCode=SudokuConstants.ConcreteNotNeededException;
        }
        catch (NoMorePossibilitiesException ex)
        {
           this.V2S_theReason=ex;
           this.V2S_ExceptionCode=SudokuConstants.NoMorePossibilitiesException;
        }
        catch (InvalidDimensionException ex)
        {
           this.V2S_theReason=ex;
           this.V2S_ExceptionCode=SudokuConstants.InvalidDimensionException;
        }
        catch (InvalidBoxEntryException ex)
        {
           this.V2S_theReason=ex;
           this.V2S_ExceptionCode=SudokuConstants.InvalidBoxEntryException;
        }
    }

    public V2S_Results V2S_ReturnResultRef()
    {
        return this.V2S_r;
    }

    public boolean isConcreteApplied()
    {
        return this.V2S_ExceptionCode!=SudokuConstants.ConcreteNotNeededException;
    }
    public int getExceptionCode()
    {
        return this.V2S_ExceptionCode;
    }
    public SudokuException getExceptionRef()
    {
        return this.V2S_theReason;
    }
    public boolean getOkExceptionStatus()
    {
        return this.V2S_ExceptionCode==SudokuConstants.EveryThingIsOk;
    }
    public FonResults getResultsAsFonResults(VirtualSudokuBoard vsb)
    {
        try
        {
            return new Fon(vsb).doFon();
        }
        catch (UnIntializedParameterException ex)
        {
           this.V2S_theReason=ex;
           this.V2S_ExceptionCode=SudokuConstants.UnIntializedParameterException;
        }
        catch (InvalidDimensionException ex)
        {
           this.V2S_theReason=ex;
           this.V2S_ExceptionCode=SudokuConstants.InvalidDimensionException;
        }
        catch (InvalidBoxEntryException ex)
        {
           this.V2S_theReason=ex;
           this.V2S_ExceptionCode=SudokuConstants.InvalidBoxEntryException;
        }
        return null;
    }
}
